enyo.kind({
/*This class is no longer in using*/
	name: "enyo.AssessmentReportRequest",
	kind: enyo.PanelBase,
	requestPageSize: 8,
	requestPageNumber: 1,
	requestPageCount: 1,
	
	requestList: null,
	
	components: [
		{kind: "PanelContent", headerContent: "Assessment Request List", onSignOut: "doSignOut", onBack: "back", flex: 1, components: [
			{className: "margin-medium", components: [
				{kind: "VirtualRepeater", name: "requestRepeater", onSetupRow: "requestRepeaterSetupRow", components: [
					{kind: "Item", layoutKind: "VFlexLayout", onclick: "requestItemClicked", style: "border: none", components: [
						{kind : "Divider", name: "cap", caption : ""},
						{kind: "Item", name: "requestInfoItem", className: "enyo-first enyo-last func-desc", components: [
							{name: "submitTimeContent", content : "", className: "divider-content"}, 
							{name: "deviceNameContent", content : "", className: "divider-content"}, 
							{name: "systemNameContent", content : "", className: "divider-content"}, 
							{name: "systemVersionContent", content : "", className: "divider-content"}
						]},
						{name: "moreButton", content : "Tap Here to Load More...", style: "margin: 5px 0px 5px 10px; font-weight: bold; font-style: italic;", showing: false}, 
					]}
				]}
			]}
		]},
		{name: "requestListService", kind: "WebService", method: "POST", onSuccess: "requestListServiceGot", onFailure: "requestListServiceFailure"}
	],
	
	create: function() {
		this.inherited(arguments);
		this.initPanel();
	},
	
	initPanel: function()
	{
		this.showScrim();
		
		//reset the controls display and status
		enyo.Data.selectedRequestID = -1;
		
		//call the service
		var obj = new Object;
		this.$.requestListService.setUrl(enyo.Config.getServiceUrl_RetrieveRequestList());
		this.$.requestListService.setHeaders(enyo.Config.getCommonServiceHeader());
		this.$.requestListService.call(obj);
	},
	
	back: function() {
		this.parentWnd.switchView("home");
	},
	
	requestListServiceGot: function(inSender, inResponse, inRequest) {
		if(inResponse.statusCode === 200) {
			if(this.requestList == null) {
				this.requestList = new Array();
			}
			
			if(inResponse.payload.requestList == null) {
				this.doError("No item found");
			} else {
				for(var i = 0; i< inResponse.payload.requestList.length; i++) {
					this.requestList.push(inResponse.payload.requestList[i]);
				}
			}
			
			//store the page count
			this.requestPageCount = inResponse.payload.pageCount;
			
			//show device list
			this.$.requestRepeater.render();
			
			this.hideScrim();	//finally, initialize work done, chagne the UI
		}
		else {
			this.doError("Error response of service (StatusCode: " + inResponse.statusCode + ")");
		}
	},
	
	requestListServiceFailure: function(inSender, inResponse, inRequest) {
		this.doError("Failed calling service");
	},
	
	requestRepeaterSetupRow: function(inSender, inIndex)
	{
		if(this.requestList == null) return;	//device list not loaded
		if (inIndex < this.requestList.length) {
			//var isRowSelected = (inIndex == this.selectedDeviceIndex);
			//this.$.item.applyStyle("background", isRowSelected ? "#000" : null);
			this.$.cap.setCaption(this.requestList[inIndex].typeName);
			
			this.$.deviceNameContent.setContent("[Host Name]"  + this.requestList[inIndex].hostname);
			this.$.systemNameContent.setContent("[System Name]"  + this.requestList[inIndex].systemNameContent);
			this.$.systemVersionContent.setContent("[System Version]"  + this.requestList[inIndex].systemVersionContent);
			var subTime = new Date(this.requestList[inIndex].timestamp);
			this.$.submitTimeContent.setContent("[Submit Time]"  + subTime);
			
			this.$.moreButton.setShowing(false);
			this.$.requestInfoItem.setShowing(true);
			this.$.cap.setShowing(true);
		
			return true;
		}
		else if(inIndex == this.requestList.length && this.requestPageNumber < inIndex != 0) {
			this.$.moreButton.setShowing(true);
			this.$.requestInfoItem.setShowing(false);
			this.$.cap.setShowing(false);
			return true;
		}
	},
	
	requestItemClicked: function(inSender, inEvent) {
		var index = inEvent.rowIndex;
		//console.log(index + "---" + this.requestList.length);
		if(index < this.requestList.length) {
			enyo.Data.selectedRequestID = this.requestList[index].guid;
			this.parentWnd.switchView("report_run");
		}
		else
		{
			//More
			this.showScrim();
		
			this.devicePageNumber ++;
			
			//call the service
			var obj = new Object;
			this.$.requestListService.setUrl(enyo.Config.getServiceUrl_RetrieveRequestList());
			this.$.requestListService.setHeaders(enyo.Config.getCommonServiceHeader());
			this.$.requestListService.call(obj);
		}
	}
});